from PySFML import sf
from rfsm import rfsm
from tower import tower
from animation import animation
from background import background
from buildings import *
from camera import camera
from interface import interface
from map import map

import psyco
psyco.full ()
    
class test1 (object) :
    def __init__ (self, cargo) :
        self.camera = camera ()
        self.tower = tower (30)
        self.interface = interface (self.tower)
        self.map = map (self.tower, self.camera.get_world())
        self.background = background (self.camera.get_world())
        self.lobby = lobby_ground (self.tower, 370, 640)
        self.lobbysize = 640
        self.lobbydir = 1
        office (self.tower, 400, 1)
        office (self.tower, 400, 2)
        office (self.tower, 472, 1)
        office (self.tower, 472, 2)
        office (self.tower, 544, 1)
        office (self.tower, 544, 2)
        office (self.tower, 450, 3)
        office (self.tower, 522, 3)
        self.map.draw_map ()
        self.event = sf.Event ()
        self.input = self.camera.get_input ()
        self.interface.set_star (0)
        self.interface.set_star (1)
    def state (self) :
        while self.camera.get_events (self.event) :
            if self.event.Type == sf.Event.Closed :
                return "quit", 0
            elif self.event.Type == sf.Event.KeyPressed :
                if self.event.Key.Code == sf.Key.W :
                    self.camera.set_velocity (None, -200.0)
                    self.camera.set_acceleration (None, 150.0)
                elif self.event.Key.Code == sf.Key.A :
                    self.camera.set_velocity (-200.0, None)
                    self.camera.set_acceleration (150.0, None)
                elif self.event.Key.Code == sf.Key.S :
                    self.camera.set_velocity (None, 200.0)
                    self.camera.set_acceleration (None, -150.0)
                elif self.event.Key.Code == sf.Key.D : 
                    self.camera.set_velocity (200.0, None)
                    self.camera.set_acceleration (-150.0, None)
        if self.input.IsMouseButtonDown (sf.Mouse.Left) :
            x, y = self.input.GetMouseX (), self.input.GetMouseY ()
            if (x > 5) & (x < self.map.x + 5) & (y > 60) & (y < self.map.y + 60) :
                self.map.click (x, y)
        #if self.lobbydir :
        #    self.lobbysize += 1
        #    if self.lobbysize == 800 :           # this code is here to
        #        self.lobbydir = 0                # check the resizing of
        #else :                                   # the lobby
        #    self.lobbysize -= 1
        #    if self.lobbysize == 640:
        #        self.lobbydir = 1
        #self.lobby.set_position (self.lobby.x, self.lobbysize)
        self.camera.clear ()
        self.camera.update (15)
        self.background.draw ()
        self.tower.update (5)
        self.tower.draw ()
        self.interface.draw () 
        self.map.draw_minimap ()
        self.camera.display ()
        return None, None

cam = camera ()
cam.setup ((800, 600) , (1280, 1080) , "OT Tests")
game = rfsm ()
game.add (test1)
game.start ("test1")
while game.update (0) :
    pass
